<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
        "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="${package.Mapper}.${table.mapperName}">
    <!--条件查询${table.comment}-->
    <select id="select${entity}Pages" resultType="${package.Entity}.${entity}">
        select
        <#list table.fields as field>
            `${field.name}`,
        </#list>
        from ${database.name}.`${table.name}`
        <where>
            <#list table.commonFields as field>
                <if><#if field?is_string>test="${field.propertyName}!='' and</#if> ${field.propertyName}!=null">
                    AND `${field.name}` = ${r"#{"}${field.propertyName}${r"}"},
                </if>
            </#list>
            and deleted=0
        </where>
        order by create_time desc,update_time desc
    </select>
<#--    <!--新增一条${table.comment}数据&ndash;&gt;-->
<#--    <insert id="insertOne${entity}" parameterType="${package.Entity}.${entity}">-->
<#--        insert into ${table.name}-->
<#--        <trim prefix="(" suffix=")" suffixOverrides=",">-->
<#--            <#list table.fields as field>-->
<#--                `${field.name}`,-->
<#--            </#list>-->
<#--        </trim>-->
<#--        values-->
<#--        <trim prefix="(" suffix=")" suffixOverrides=",">-->
<#--            <#list table.fields as field>-->
<#--                ${r"#{"}${field.propertyName}${r"}"},-->
<#--            </#list>-->
<#--        </trim>-->
<#--    </insert>-->
<#--    <!--更新一条${table.comment}数据&ndash;&gt;-->
<#--    <update id="updateOne${entity}" parameterType="${package.Entity}.${entity}">-->
<#--        update ${table.name}-->
<#--        <set>-->
<#--            <#list table.fields as field>-->
<#--                <if test="${field.propertyName}!='' and ${field.propertyName}!=null">-->
<#--                    `${field.name}` = ${r"#{"}${field.propertyName}${r"}"},-->
<#--                </if>-->
<#--            </#list>-->
<#--        </set>-->
<#--        where id = ${r"#{id}"}-->
<#--    </update>-->
<#--    <!--批量删除${table.comment}数据&ndash;&gt;-->
<#--    <delete id="delete${entity}s" parameterType="java.util.List">-->
<#--        update ${table.name} set deleted=1 where id in-->
<#--        <foreach collection="ids" item="id" open="(" separator="," close=")">-->
<#--            ${r"#{id}"}-->
<#--        </foreach>-->
<#--    </delete>-->
    <!--按条件记录${table.comment}的个数-->
    <select id="count${entity}ByCondition" resultType="java.lang.Integer">
        select COUNT(id)
        from ${database.name}.`${table.name}`
        <where>
            <#list table.fields as field>
                <if test="<#if field?is_string>${field.propertyName}!='' and</#if> ${field.propertyName}!=null">
                    AND `${field.name}`=${r"#{"}${field.propertyName}${r"}"}
                </if>
           </#list>
        </where>
    </select>
</mapper>
